"""
计算交叉熵
"""
import math
import numpy as np

y_true = [0,1,0,0,0] # 真实概率
y_pred1 = [0.1,0.6,0.1,0.1,0.1]
y_pred2 = [0.1,0.7,0.1,0.05,0.05]
y_pred3 = [0.1,0.8,0.04,0.03,0.03]
cross_entropy1 = 0.0
cross_entropy2 = 0.0
cross_entropy3 = 0.0
for i in range(len(y_true)):
    cross_entropy1 += y_true[i] * math.log(y_pred1[i])
    cross_entropy2 += y_true[i] * math.log(y_pred2[i])
    cross_entropy3 += y_true[i] * math.log(y_pred3[i])
print('交叉熵1：',-cross_entropy1)
print('交叉熵2：',-cross_entropy2)
print('交叉熵3：',-cross_entropy3)


# total_samples = 600000
# batch_size = 100
# total_batch = int(total_samples / batch_size)
# total_epoch = 49
#
# for epoch in range(total_epoch):
#     for batch in range(batch_size):
#         梯度下降